package com.hvilela.filters;

/**
 * @author Henrique de Souza Vilela
 * henrique.vilela@gmail.com
 */
import java.awt.Color;
import java.awt.image.RGBImageFilter;

public class GrayscaleFilter extends RGBImageFilter {

	@Override
	public int filterRGB(int x, int y, int rgb) {
		int r, g, b, gray;

		Color c = new Color(rgb);
		r = c.getRed();
		g = c.getGreen();
		b = c.getBlue();

		gray = (int) Math.round(r * 0.3 + g * 0.59 + b * 0.11);

		c = new Color(gray, gray, gray);
		return c.getRGB();
	}
}